#include <REGX52.H>
#include <..\XC51.h>

unsigned char pwm_left_val = 160;
unsigned char pwm_right_val = 160;
unsigned char pwm_t;

void timer0() interrupt 5
{
	pwm_t++;//?????
	if(pwm_t == 255)
		pwm_t = EN1 = EN2 = 0;
	if(pwm_left_val == pwm_t)
		EN1 = 1;		
	if(pwm_right_val == pwm_t)
		EN2 = 1;			 
}

int main(void)
{
		T2MOD = 0;
		T2CON = 0;
		TH2 = 220;
		TL2 = 220;
	
	

    TR2 = 1;
		TR2 = 1;
		ET2 = 1;
		EA	= 1;
		while(1)
	{
		
		if (left_find == 0 && right_find == 0)
		{
			advance();
		}
		else
		{
			if (left_find == 1 && right_find == 0)
			{
				left_turn();
			}
			if (left_find == 0 && right_find == 1)
			{
				right_turn();
			}
		}
		if (left_find == 1 && right_find == 1)
		{
			stop();
		}
		
	}
	
}